package com.zyh.scs.admin.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zyh.scs.admin.api.dto.UserHistoryRechargeDTO;
import com.zyh.scs.admin.api.entity.UserHistoryRecharge;
import com.zyh.scs.admin.api.utils.UserTypeToNameUtil;
import com.zyh.scs.admin.mapper.UserHistoryRechargeMapper;
import com.zyh.scs.admin.service.UserHistoryRechargeService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * @author hwh
 * @ClassName: $
 * @Description: $
 * @Date $
 * @Version 1.0
 */
@Slf4j
@Service
@RequiredArgsConstructor
public class UserHistoryRechargeServiceImpl extends ServiceImpl<UserHistoryRechargeMapper, UserHistoryRecharge> implements UserHistoryRechargeService {

    @Override
    public IPage getRechargePage(Page page, UserHistoryRechargeDTO userHistoryRechargeDTO) {
        Page<UserHistoryRecharge> userHistoryRechargePage = new Page<>(page.getCurrent(), page.getSize());
        LambdaQueryWrapper<UserHistoryRecharge> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.ge(StrUtil.isNotBlank(userHistoryRechargeDTO.getBeginTime()), UserHistoryRecharge::getRechargeTime, UserTypeToNameUtil.stringToLocalBeginTime(userHistoryRechargeDTO.getBeginTime()))
                .le(StrUtil.isNotBlank(userHistoryRechargeDTO.getEndTime()), UserHistoryRecharge::getRechargeTime, UserTypeToNameUtil.stringToLocalEndTime(userHistoryRechargeDTO.getEndTime()))
                .orderByDesc(UserHistoryRecharge::getCreateTime,UserHistoryRecharge::getHistoryId);
        return this.page(userHistoryRechargePage, queryWrapper);
    }
}
